package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.HouseInfoTitleBean;

import java.util.List;

public class HousePublicItemAdapter extends BaseQuickAdapter<HouseInfoTitleBean.HouseInfoConfiguration,BaseViewHolder> {
    int selectSexIndex=-1;
    public HousePublicItemAdapter(@Nullable List<HouseInfoTitleBean.HouseInfoConfiguration> data) {
        super(R.layout.housepublic_item_item,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HouseInfoTitleBean.HouseInfoConfiguration item) {
        helper.<TextView>getView(R.id.housepublic_item_item_tv).setText(item.getName());
        helper.<TextView>getView(R.id.housepublic_item_item_tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setSelect(!item.isSelect());
                if (item.isSelect())
                {
                  if (selectSexIndex!=-1&&(item.getName().equals("限女生")||item.getName().equals("限男生")))
                    {
                        getData().get(selectSexIndex).setSelect(false);
                    }
                  if ((item.getName().equals("限女生")||item.getName().equals("限男生")))
                    {
                        selectSexIndex=helper.getPosition();
                    }

                }else {
                    if (item.getName().equals("限女生")||item.getName().equals("限男生"))
                    {
                        selectSexIndex=-1;
                    }
               }
                notifyDataSetChanged();
            }
        });
          if (item.isSelect())
          {
              helper.<TextView>getView(R.id.housepublic_item_item_tv).setTextColor(ArmsUtils.getColor(mContext,R.color.color_191919));
              helper.<TextView>getView(R.id.housepublic_item_item_tv).setBackgroundResource(R.drawable.square_yellow_bg);
          }else {
              helper.<TextView>getView(R.id.housepublic_item_item_tv).setTextColor(ArmsUtils.getColor(mContext,R.color.white));
              helper.<TextView>getView(R.id.housepublic_item_item_tv).setBackgroundResource(R.drawable.square_gray_bg);
          }
    }
}
